package thread;

public class ThreadDemo9 {
    private static boolean flag = false;

    public static void main(String[] args) {
        Thread t = new Thread(() -> {
            while(!flag){
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

        t.start();
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("使 t 线程提前终止");
        flag = true;

        System.out.println("hello main");
    }
}
